package com.itheima;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @auther Macrydy
 * @date 2020/7/11 14:30
 */
public class ThreadPool02 {
    public static void main(String[] args) {
        //默认线程池传入参数指定线程池最大线程数
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        //ThreadPoolExecutor为ExecutorService接口的实现类，所以把executorService强转为hreadPoolExecutor，调用其特有方法
        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
        //获取线程池中线程数量
        System.out.println(pool.getPoolSize());//0

        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName() + "在执行了");
        });

        executorService.submit(()->{
            System.out.println(Thread.currentThread().getName() + "在执行了");
        });

        //获取线程池中线程数量
        System.out.println(pool.getPoolSize());//2
//        executorService.shutdown();
    }
}
